import { defineStore } from 'pinia';
import { handleTree } from '@/sheep/util';
const src = 'https://www.zhangfkj.cn/zfkj/535be5ffcff09e39dae44365489315842aec8cc02d6a4d6d99717b98ba367882.jpg'
const category = defineStore({
  id: 'category',
  state: () => ({
    category: [],
    pages:{
      base:{},
      home:{

      },
      user:{
        userBg:'https://www.zhangfkj.cn/zfkj/18ec2fdf076eb9695bdbc6971dd6a055bcacc78f52ff5286242b2f62b1fc976f.png',
        avatarKefu:'https://www.zhangfkj.cn/zfkj/2c98c993b19b47a9c395866e2a2d9b22f82c74f7197abe08d10177fe8a5b4c4d.png',
        avatarOrder:'https://www.zhangfkj.cn/zfkj/6a3a54e38bd10b559a332ac00f3c1360dd50d0a7493cf5cea12588b2b6ce13e0.png',
        avatarDefault:'https://www.zhangfkj.cn/zfkj/252f24427973a662c97e98c5fe1cf1eed1480862793917b5d4534aaffeb8c414.png',
        coin:'https://www.zhangfkj.cn/zfkj/d9259f13c4e944f716af209d0d4b2757e2871d2ba945d4ac3b8536b197a170d3.png',
        coin7:'https://www.zhangfkj.cn/zfkj/3c811e41dc66220a367a2c411bd190ee9781f875e5c9762e7cb2014dc966d9c5.png',
        coinSign:'https://www.zhangfkj.cn/zfkj/f3c79a552e4e2244283bb8622f0e92d96beea2c88ceedff679d3a3ec53d398ae.png',
      }
    },
    album:{
      default:{
        topPic:'https://www.zhangfkj.cn/zfkj/99bdd8789310d1dfc2611c6fd217f66667b9ec1b587e5c13394f10956896ad06.jpeg',
        bgColor:'#efddcf'
      },
      hotList: [
        {
          name: '新品上市',
          smallPic: src,
          topPic: src,
          bgColor: '#ffca8e',
        },
        {
          name: '滋补保健',
          smallPic: src,
          topPic: src,
          bgColor: '#fec487',
        }, {
          name: '厨房新品',
          smallPic: src,
          topPic: src,
          bgColor: '#f0ece4',
        }, {
          name: '懒人清洁',
          smallPic: src,
          topPic: src,
          bgColor: '#bbdef2',
        }, {
          name: '家居焕新',
          smallPic: src,
          topPic: src,
          bgColor: '#ffc7d4',
        }, {
          name: '男士爆款',
          smallPic: src,
          topPic: src,
          bgColor: '#eae9ff',
        }, {
          name: '百万补贴',
          smallPic: src,
          topPic: src,
          bgColor: '#febd09',
        }, {
          name: '必囤护肤',
          smallPic: src,
          topPic: src,
          bgColor: '#f8ccdd',
        }, {
          name: '网红家电',
          smallPic: src,
          topPic: src,
          bgColor: '#e6e5ff',
        },
      ],

    },
    search: {
      history: [],
      suggest:[
        {
          'searchTerm': '五粮液',
        },
        {
          'searchTerm': '抽纸',
        },
        {
          'searchTerm': '充电宝',
        },
        {
          'searchTerm': '无人机',
        },
        {
          'searchTerm': '血压计',
        },
        {
          'searchTerm': '扫地机器人',
        },
        {
          'searchTerm': '剃须刀',
        },
        {
          'searchTerm': '吹风机',
        },
        {
          'searchTerm': '四件套',
        },
        {
          'searchTerm': '耳机',
        },
        {
          'searchTerm': '电话手表',
        },
      ]
    },

  }),
  getters: {},
  actions: {
    setCategory(list = []) {
      if (list.length > 0) {
        this.category = list;
        return;
      }
      // TODO 李望龙：1）等接口
      // const { data, code } = CategoryApi.getActivityCategoryList();
      // if (code !== 0) {
      //   return;
      // }
      // this.category = data;
      list = [
        { id: 1, pid: 0, name: 'home', desc: '首页' },
        { id: 3, pid: 1, name: 'home-top', title: '限时抢购', subTitle: '副标题' },


        { id: 2, pid: 3, name: 'home-top', title: '限时抢购', subTitle: '副标题' },
        { id: 4, pid: 3, name: 'home-top', title: '电器兑换', subTitle: '副标题' },
        { id: 5, pid: 3, name: 'home-top', title: '居家兑换', subTitle: '副标题' },
        { id: 6, pid: 3, name: 'home-top', title: '保健兑换', subTitle: '副标题' },
        { id: 7, pid: 3, name: 'home-top', title: '美妆兑换', subTitle: '副标题' },
        { id: 8, pid: 1, name: 'home-bottom', desc: '首页-bottom' },
      ];
      const cate = handleTree(list, 'id', 'pid', 'children', 0);
      console.log(cate);
      this.category = cate;
      console.log(this.category);
    },
    setHistory(list) {
      this.search.history = list;
    },
    addHistory(obj){
      if(obj.length === 0){ return }
      const index = this.search.history.indexOf(obj)
      if(index > -1){
        this.search.history.splice(index, 1);
        this.search.history.unshift(obj)
        return
      }
      this.search.history.unshift(obj)
    }
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'category-store',
      },
    ],
  },
});

export default category;
